<template>
  <div class="divBox">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div class="filter-container">
          <el-form size="small" label-width="150px" :inline="true">
            <el-form-item :label="$t('reconciliationstatus')" class="mr20">
              <el-select
                v-model="tableFrom.status"
                :placeholder="$t('please83')"
                @change="getList"
              >
                <el-option :label="$t('all')" value="" />
                <el-option :label="$t('unconfirmed')" value="0" />
                <el-option :label="$t('rejected')" value="1" />
                <el-option :label="$t('confirmed')" value="2" />
              </el-select>
            </el-form-item>
            <el-form-item :label="$t('timeselection')" class="mr10">
              <el-date-picker
                v-model="timeVal"
                type="daterange"
                align="right"
                unlink-panels
                format="yyyy 年 MM 月 dd 日"
                value-format="yyyy/MM/dd"
                :range-separator="$t('to')"
                :start-placeholder="$t('startdate')"
                :end-placeholder="$t('enddate')"
                :picker-options="pickerOptions"
                @change="onchangeTime"
              />
            </el-form-item>
            <el-form-item :label="$t('keywords')" class="mr10">
              <el-input
                v-model="tableFrom.keyword"
                @keyup.enter.native="getList"
                :placeholder="$t('please18')"
                class="selWidth"
              >
                <el-button
                  slot="append"
                  icon="el-icon-search"
                  class="el-button-solt"
                  @click="getList"
                />
              </el-input>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <el-table
        v-loading="listLoading"
        :data="tableData.data"
        style="width: 100%"
        size="mini"
        class="table"
        highlight-current-row
      >
        <el-table-column type="expand">
          <template slot-scope="props">
            <el-form label-position="left" inline class="demo-table-expand">
              <el-form-item :label="$t('bankcardholder')">
                <span>{{ props.row.bank_name | filterEmpty }}</span>
              </el-form-item>
              <el-form-item :label="$t('bankaddress')">
                <span>{{ props.row.bank_address | filterEmpty }}</span>
              </el-form-item>
              <el-form-item :label="$t('transfertime')">
                <span>{{ props.row.accounts_time | filterEmpty }}</span>
              </el-form-item>
              <el-form-item :label="$t('remarks')">
                <span>{{ props.row.mark | filterEmpty }}</span>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column prop="reconciliation_id" label="ID" width="60" />
        <el-table-column
          prop="create_time"
          :label="$t('creationtime')"
          min-width="150"
        />
        <el-table-column
          prop="admin.real_name"
          :label="$t('backgroundadministrator')"
          min-width="100"
        />
        <el-table-column
          prop="merchant.mer_name"
          :label="$t('storename')"
          min-width="150"
        />
        <el-table-column :label="$t('reconciliationstatus')" min-width="80">
          <template slot-scope="scope">
            <span>{{ scope.row.status | reconciliationStatusFilter }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="price"
          :label="$t('totalreconciliationamount')"
          min-width="120"
        />
        <el-table-column
          prop="charge"
          :label="$t('totaldeductionamount')"
          min-width="120"
        />
        <el-table-column
          prop="bank"
          :label="$t('bankofdepositofbankcard')"
          min-width="180"
        />
        <el-table-column
          :label="$t('bankcardno')"
          min-width="150"
          prop="bank_number"
        />
        <el-table-column prop="" :label="$t('transferstatus')" min-width="80">
          <template slot-scope="scope">
            <span>{{ scope.row.is_accounts | accountStatusFilter }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('operation')" min-width="200" fixed="right">
          <template slot-scope="scope">
            <router-link
              :to="{
                path:
                  roterPre +
                  '/accounts/reconciliation/order/' +
                  scope.row.reconciliation_id,
              }"
            >
              <el-button type="text" size="small" class="mr10">{{
                $t("vieworder")
              }}</el-button>
            </router-link>
            <el-button
              type="text"
              size="small"
              @click="onAccounts(scope.row.reconciliation_id)"
              >{{ $t("confirmreconciliation") }}</el-button
            >
            <el-button
              type="text"
              size="small"
              @click="onMark(scope.row.reconciliation_id)"
              >{{ $t("remarks") }}</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="block mb20">
        <el-pagination
          :page-sizes="[10, 20, 30, 40]"
          :page-size="tableFrom.limit"
          :current-page="tableFrom.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.total"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </div>
    </el-card>

    <el-dialog
      :title="$t('reconciliationstatus')"
      :visible.sync="dialogVisible"
      width="450px"
      :before-close="handleClose"
    >
      <el-form
        ref="ruleForm"
        :model="ruleForm"
        :rules="rules"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item :label="$t('reconciliationstatus')" prop="status">
          <el-radio-group v-model="ruleForm.status">
            <el-radio label="0">{{ $t("confirmreconciliation") }}</el-radio>
            <el-radio label="1">{{ $t("rejectreconciliation") }}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            :loading="loading"
            @click="submitForm('ruleForm')"
            >{{ $t("submit") }}</el-button
          >
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
import {
  reconciliationListApi,
  reconciliationStatusApi,
  reconciliationMarkApi,
} from "@/api/accounts";
import { roterPre } from "@/settings";
export default {
  name: "Record",
  data() {
    return {
      loading: false,
      roterPre: roterPre,
      timeVal: [],
      pickerOptions: {
        shortcuts: [
          {
            text: this.$t("lastweek"),
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: this.$t("lastmonth"),
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: this.$t("thelastthreemonths"),
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      listLoading: true,
      tableData: {
        data: [],
        total: 0,
      },
      tableFrom: {
        page: 1,
        limit: 10,
        date: "",
        status: "",
        keyword: "",
        reconciliation_id: this.$route.query.reconciliation_id
          ? this.$route.query.reconciliation_id
          : "",
      },
      ruleForm: {
        status: "0",
      },
      dialogVisible: false,
      rules: {
        status: [
          {
            required: true,
            message: this.$t("reconciliationstatus"),
            trigger: "change",
          },
        ],
      },
      reconciliationId: 0,
    };
  },
  computed: {},
  mounted() {
    this.getList();
  },
  methods: {
    onMark(id) {
      this.$modalForm(reconciliationMarkApi(id)).then(() => this.getList());
    },
    onAccounts(id) {
      this.reconciliationId = id;
      this.dialogVisible = true;
    },
    handleClose() {
      this.dialogVisible = false;
      this.$refs["ruleForm"].resetFields();
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.loading = true;
          reconciliationStatusApi(this.reconciliationId, this.ruleForm)
            .then((res) => {
              this.$message.success(res.message);
              this.loading = false;
              this.handleClose();
              this.getList();
            })
            .catch((res) => {
              this.$message.error(res.message);
              this.loading = false;
            });
        } else {
          return false;
        }
      });
    },
    // 具体日期
    onchangeTime(e) {
      this.timeVal = e;
      this.tableFrom.date = this.timeVal ? this.timeVal.join("-") : "";
      this.getList();
    },
    // 列表
    getList() {
      this.listLoading = true;
      reconciliationListApi(this.tableFrom)
        .then((res) => {
          this.tableData.data = res.data.list;
          this.tableData.total = res.data.count;
          this.listLoading = false;
        })
        .catch((res) => {
          this.listLoading = false;
          this.$message.error(res.message);
        });
    },
    pageChange(page) {
      this.tableFrom.page = page;
      this.getList();
    },
    handleSizeChange(val) {
      this.tableFrom.limit = val;
      this.chkName = "";
      this.getList();
    },
  },
};
</script>

<style lang="scss" scoped>
.divBox {
  ::v-deep.el-card__header {
    padding: 18px 20px 0 18px !important;
  }
}
.spBlock {
  cursor: pointer;
}
.check {
  color: #00a2d4;
}
.tabPop {
  ::v-deep .el-popover {
    width: 100px !important;
  }
}
.fang {
  display: inline-block;
  position: relative;
  border: 1px solid #dcdfe6;
  border-radius: 2px;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  width: 14px;
  height: 14px;
  background-color: #fff;
  z-index: 1;
  -webkit-transition: border-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46),
    background-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46);
  transition: border-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46),
    background-color 0.25s cubic-bezier(0.71, -0.46, 0.29, 1.46);
}
.el-table ::v-deep.DisabledSelection .cell .el-checkbox__inner {
  margin-left: -30px;
  position: relative;
}
.el-table ::v-deep.DisabledSelection .cell:before {
  content: "全选";
  position: absolute;
  right: 11px;
}
.demo-table-expand {
  ::v-deep label {
    width: 111px !important;
    color: #99a9bf;
  }
}
.selWidth {
  width: 300px;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
  font-size: 12px;
}
.el-icon-arrow-down {
  font-size: 12px;
}
.tabBox_tit {
  width: 60%;
  font-size: 12px !important;
  margin: 0 2px 0 10px;
  letter-spacing: 1px;
  padding: 5px 0;
  box-sizing: border-box;
}
</style>
